package com.hou.cassecurity.compent;

import com.hou.cassecurity.mapper.UserMapper;
import com.hou.cassecurity.pojo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.*;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class UserNamePwdDetails implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        System.out.println("当前认证成功的用户名:" + s);

        //加载用户权限信息，注意这里已经由cas完成认证，不再需要加载密码了

        //准备权限集合
        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();

        //注意这里user中的密码可以不写，因为cas已经验证过了，现在只是需要把该用户的权限注入security中，但是也不能是null，null就会报错
        return new User(s, "1",true,true,true,true, grantedAuthorities);
    }
}
